<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AreaAcademica
 *
 * @author markos
 */
class VirtualLabs_Admin_AreaAcademica extends VirtualLabs_Admin_Dao {

    const TABLE_NAME = 'area_academica';
    /**
     * 
     * @param type $fields
     * @param type $where
     * @return type
     * @throws Exception
     */
    public function getAreasAcademicas($fields = array(), $where = array()) {
        $db = Zend_Db_Table::getDefaultAdapter();
        $select = $db->select()->from("area_academica", $fields);
        foreach ($where as $key => $value) {
            $select->where("$key {$value['criteria']} ?", $value['value']);
        }

        try {
            return $db->fetchAll($select);
        } catch (Exception $e) {
            $logger = Zend_Registry::get(VirtualLabs_Exception::ERROR_LOG);
            $logger->err($e->getMessage());
            $logger->err($e->getTraceAsString());
            throw $e;
        }
    }

    /**
     * 
     * @param type $fields
     * @param type $where
     * @return type
     * @throws Exception
     */
    public function getAreaAcademica($fields = array(), $where = array()) {
        $db = Zend_Db_Table::getDefaultAdapter();
        $select = $db->select()->from(VirtualLabs_Admin_AreaAcademica::TABLE_NAME, $fields);
        foreach ($where as $key => $value) {
            $select->where("$key {$value['criteria']} ?", $value['value']);
        }
        try {
            $debug = Zend_Registry::get(VirtualLabs_Common::DEBUG_LOG);
            $debug->debug("[ getAreaAcademica ] $select");
            return $db->fetchRow($select);
        } catch (Exception $e) {
            $logger = Zend_Registry::get(VirtualLabs_Exception::ERROR_LOG);
            $logger->err($e->getMessage());
            $logger->err($e->getTraceAsString());
            throw $e;
        }
    }
    
    /**
     * 
     * @param type $codigoAreaAcademica
     * @return boolean
     * @throws Exception
     */
    public function deleteAreaAcademica($codigoAreaAcademica) {
        try {
            $this->delete(VirtualLabs_Admin_AreaAcademica::TABLE_NAME, $codigoAreaAcademica);
            return true;
        } catch (Exception $e) {
            $logger = Zend_Registry::get(VirtualLabs_Exception::ERROR_LOG);
            $logger->err($e->getMessage());
            $logger->err($e->getTraceAsString());
            throw $e;
        }
    }
    
    /**
     * 
     * @param type $data
     * @param type $codigoAacademica
     * @return boolean
     * @throws Exception
     */
    public function save($data, $codigoAacademica = null) {
        try {
            $db = Zend_Db_Table::getDefaultAdapter();
            if (!is_null($codigoAacademica)) {
                $db->update(VirtualLabs_Admin_AreaAcademica::TABLE_NAME, $data, $codigoAacademica);
            } else {
                $db->insert(VirtualLabs_Admin_AreaAcademica::TABLE_NAME, $data);                
            }
            return true;
        } catch (Exception $e) {
            $logger = Zend_Registry::get(VirtualLabs_Common::DEBUG_LOG);
            $logger->debug($e->getMessage());
            $logger->debug($e->getTraceAsString());
            throw $e;
        }
    }

}

?>
